/*
 * @Author: Quinn
 * @Date: 2023-05-21 15:49:58
 * @LastEditors: 叽歪小Q
 * @Description:
 */
let host = window.location.origin;

export const API_HOST = import.meta.env.VITE_APP_HOST;

export const BASE = import.meta.env.BASE_URL;
// import.meta.env.VITE_IMG_HOST
export const IMG_HOST = 'https://';

export const LOGIN_PATH = `${BASE}nested/`;

export const STORE_LEDGER_COLUMN = [
  {
    label: "ID",
    prop: "id",
    minWidth: "120px",
  },
  {
    label: "订单ID",
    prop: "orderId",
    minWidth: "120px",
  },
  {
    label: "门店名称",
    prop: "storeName",
    minWidth: "120px",
  },
  {
    label: "状态",
    prop: "status",
    minWidth: "120px",
  },
  {
    label: "状态",
    prop: "status",
    minWidth: "120px",
  },
  {
    label: "下单时间",
    prop: "createdTime",
    minWidth: "160px",
  },
  {
    label: "修改时间",
    prop: "updatedTime",
    minWidth: "180px",
  },
  {
    label: "货拉拉",
    prop: "货拉拉amount",
    minWidth: "120px",
  },
  {
    label: "仓库货架货拉拉",
    prop: "仓库货架货拉拉amount",
    minWidth: "120px",
  },
  {
    label: "安装卸货费",
    prop: "安装卸货费amount",
    minWidth: "120px",
  },
  {
    label: "二次上门",
    prop: "二次上门amount",
    minWidth: "120px",
  },
  {
    label: "三次上门",
    prop: "三次上门amount",
    minWidth: "120px",
  },
  {
    label: "四次上门",
    prop: "四次上门amount",
    minWidth: "120px",
  },
  {
    label: "改货架/退货架费用",
    prop: "改货架/退货架费用amount",
    minWidth: "120px",
  },
  {
    label: "工厂问题",
    prop: "工厂问题amount",
    minWidth: "120px",
  },
  {
    label: "欠数破损补发",
    prop: "欠数破损补发amount",
    minWidth: "120px",
  },
  {
    label: "其他（车费、住宿费、滴滴等）",
    prop: "其他（车费、住宿费、滴滴等）amount",
    minWidth: "120px",
  },
];

export const $acc = (function () {
  /**
   * floatObj 包含加减乘除四个方法，能确保浮点数运算不丢失精度
   * floatObj.add(0.1, 0.2) >> 0.3
   * floatObj.mul(19.9, 100) >> 1990
   */

  function toFixed(num, s) {
    var times = Math.pow(10, s);
    var des = num * times + 0.5;
    des = parseInt(des, 10) / times;
    return des;
  }

  function isInteger(obj) {
    return Math.floor(obj) === obj;
  }

  function toInteger(floatNum) {
    var ret = {
      times: 1,
      num: 0,
    };
    var isNegative = floatNum < 0;
    if (isInteger(floatNum)) {
      ret.num = floatNum;
      return ret;
    }
    var strfi = floatNum + "";
    var dotPos = strfi.indexOf(".");
    var len = strfi.substr(dotPos + 1).length;
    var times = Math.pow(10, len);
    var intNum = parseInt(Math.abs(floatNum) * times + 0.5, 10);
    ret.times = times;
    if (isNegative) {
      intNum = -intNum;
    }
    ret.num = intNum;
    return ret;
  }

  function operation(a, b, digits, op) {
    var o1 = toInteger(a);
    var o2 = toInteger(b);
    var n1 = o1.num;
    var n2 = o2.num;
    var t1 = o1.times;
    var t2 = o2.times;
    var max = t1 > t2 ? t1 : t2;
    var result = null;
    switch (op) {
      case "add":
        if (t1 === t2) {
          // 两个小数位数相同
          result = n1 + n2;
        } else if (t1 > t2) {
          // o1 小数位 大于 o2
          result = n1 + n2 * (t1 / t2);
        } else {
          // o1 小数位 小于 o2
          result = n1 * (t2 / t1) + n2;
        }
        return result / max;
      case "sub":
        if (t1 === t2) {
          result = n1 - n2;
        } else if (t1 > t2) {
          result = n1 - n2 * (t1 / t2);
        } else {
          result = n1 * (t2 / t1) - n2;
        }
        return result / max;
      case "mul":
        result = (n1 * n2) / (t1 * t2);
        return result;
      case "div":
        result = (n1 / n2) * (t2 / t1);
        return result;
    }
  }

  function add(a, b, digits) {
    return operation(a, b, digits, "add");
  }

  function sub(a, b, digits) {
    return operation(a, b, digits, "sub");
  }

  function mul(a, b, digits) {
    return operation(a, b, digits, "mul");
  }

  function div(a, b, digits) {
    return operation(a, b, digits, "div");
  }
  return {
    toFixed,
    add,
    sub,
    mul,
    div,
  };
})();
